<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面向字节标称-cookie</title>
</head>

<body>
    <script>
        // cookie 属于某个域名 domain 拿不到掘金的cookie
        // console.log(document.cookie);
        // cookie 的优点是每次传输都可以带上，缺点：是他是一段文本，拿到某一个cookie name的值会比较难
        const cookieObj = {};
        const cookieStr = "_ga=GA1.2.859444289.1622087696; ttcid=fb1b750b162943f7bbd15177c7be89a440; passport_csrf_token_default=176f26131b5a3c6d1c1ae2148f01fecb; passport_csrf_token=176f26131b5a3c6d1c1ae2148f01fecb; MONITOR_WEB_ID=deb4c8fd-931e-4afc-8ca3-97075e673ed4; _gid=GA1.2.2112471165.1630581351; _gat=1; tt_scid=U3.nnsVm8m1fkZAyCGC1Z1OTDTYDOnfwuEYDTWxjAUaDhcEqmfOJIog6VdNLNSy5a036"
        const parseCookie = str =>
            str
            .split(';')
            .map(v => v.split('='))
            // reduce是把数组推平的方法
            .reduce((acc, v) => {
                acc[v[0]] = v[1]
                return acc
            }, {})

        console.log(parseCookie(cookieStr));
    </script>
</body>

</html>